//app.js
const regeneratorRuntime = require("/utils/runtime")	//async插件
import {getLocation,getSetAndUserInfo,getOpenid} from '/utils/wxApi'

App({
	onLaunch:function () {
		//用户经纬度预取
		(async function(app) {
			let location = await getLocation(app)
			if(location.latitude){
				app.globalData.location = location
			}
		})(this)
		
		// 登录
		getOpenid(this).then(info=>{
			if(info.openid && info.openid.length>1){
				this.globalData.openid = info.openid
			}
			
			if(info.carPassenger){
				this.globalData.dbUserData = info.carPassenger
			}
			
			//用户信息预取
			return getSetAndUserInfo(this)
			
		}).then(userInfo=>{
			
			this.globalData.userInfo = userInfo
			
		})
	},
	globalData: {
		userInfo:null,
		dbUserData:null,
		location:null,
		openid:null
	}
})